<?php
/**
 * Created by PhpStorm.
 * User: 123
 * Date: 2020/4/18
 * Time: 20:11
 */
namespace app\index\controller;

use app\common\controller\Frontend;
use app\common\library\Page;

/**
 * 运营推广控制器
 * Class Extension
 * @package app\index\controller
 */
class Extension extends Frontend
{

    protected $noNeedLogin = '*';
    protected $noNeedRight = '*';
    protected $layout = '';

    public function index()
    {
        $id=!empty($this->request->param('id'))?intval($this->request->param('id')):0;
        if(empty($id))$this->error('文章分类不存在！',url('/index'));

        $cpage=!empty($this->request->param('cpage'))?intval($this->request->param('cpage')):1;
        $total=!empty($this->request->param('total'))?intval($this->request->param('total')):10;
        $identify=!empty($this->request->param('identify'))?trim($this->request->param('identify')):'index';

        //文章分类信息作为页面信息
        $pageInfo=db('article_category')->where('id='.$id)->field('id,title,keywords,description,name,info,pid')->find();
        if(empty($pageInfo)) $this->error('文章分类不存在！',url('/index'));

        $start=($cpage-1)*$total;
        $url='/extension/'.$identify.'/'.$id.'/';

        //分类下所有文章
        $articleList=db('article')->where('category_id='.$id)->order('sort desc,id desc')->field('id,title,thumb,info,from_unixtime(createtime,"%Y-%m-%d") as createtime,clicks,author')->limit($start,$total)->select();
        $count=db('article')->where('category_id='.$id)->count();

        //分页
        $page=new Page();
        $show=$page->create($count,$cpage,$total,$url);

        //父分类下的子分类
        $childrenPlist=db('article_category')->where('pid='.$pageInfo['pid'])->order('sort desc,id asc')->field('id,name')->select();

        //banner
        $bannerList=db('extension_banner')->order('sort desc,id asc')->field('title,thumb,link')->select();

        $this->assign('pageInfo',$pageInfo);
        $this->assign('articleList',$articleList);
        $this->assign('show',$show);
        $this->assign('childrenPlist',$childrenPlist);
        $this->assign('bannerList',$bannerList);
        $this->assign('id',$id);
        $this->assign('identify_1',$identify);

        return $this->view->fetch();
    }

}